/*  JEVEMon, A Java-based EVEMon clone.
Copyright (C) 2011, Raul Ruiz

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package jeveme;

import javax.swing.JLabel;
import java.util.Calendar;
import java.util.TimeZone;

/**
 *
 * @author Raul Ruiz
 */
public class UpdateEveTime implements Runnable {
    
    /**
     * 
     */
    private JLabel eveTimeLabel;
    
    /**
     * 
     */
    private static final String TIMEBASE = "EVE Time: ";
    
    /**
     * 
     */
    private static final String TIMETERMINATOR = " //";
    
    /**
     * 
     * @param label 
     */
    public UpdateEveTime(JLabel label) {
        eveTimeLabel = label;
    }
    
    /**
     * 
     */
    public void run() {
        String hour;
        String minute;
        
        TimeZone tz = TimeZone.getTimeZone("GMT");
        Calendar c = Calendar.getInstance(tz);
        
        if(c.get(Calendar.HOUR_OF_DAY) < 10) {
            hour = "0" + Integer.toString(c.get(Calendar.HOUR_OF_DAY));
        }
        else {
            hour = Integer.toString(c.get(Calendar.HOUR_OF_DAY));
        }
       
        if(c.get(Calendar.MINUTE) < 10) {
            minute = "0" + Integer.toString(c.get(Calendar.MINUTE));
        }
        else {
            minute = Integer.toString(c.get(Calendar.MINUTE));
        }

        String time = hour + ":" + minute;
        
        eveTimeLabel.setText(TIMEBASE + time + TIMETERMINATOR);
        
    }
}
